package com.swiftair.view
{
	import com.swiftair.ApplicationFacade;
	import com.swiftair.view.components.SettingsWindow;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

    public class ApplicationMediator extends Mediator implements IMediator
    {
        // Cannonical name of the Mediator
        public static const NAME:String = "ApplicationMediator";
		// Application dialogs
		private var _settings:SettingsWindow;

        public function ApplicationMediator(viewComponent:Swiftair) {
            super(NAME, viewComponent);
			_settings = new SettingsWindow();
		}

        override public function onRegister():void {
            // Create and register Mediators
            // components that were instantiated by the mxml application 
			facade.registerMediator(new SettingsMediator(_settings));
			facade.registerMediator(new StatusesListMediator(app.homeList));
			facade.registerMediator(new StatusesListMediator(app.mentionsList));
        }

        override public function listNotificationInterests():Array {
            return [
						ApplicationFacade.VIEW_MAIN_SCREEN,
						ApplicationFacade.VIEW_SETTINGS_SCREEN,
						ApplicationFacade.MODEL_ACCESS_GRANTED
					];
        }

        override public function handleNotification(note:INotification):void {
            switch (note.getName()) {
				case ApplicationFacade.VIEW_MAIN_SCREEN:
					break;
				case ApplicationFacade.VIEW_SETTINGS_SCREEN:
					_settings.open(true);
					break;
				case ApplicationFacade.MODEL_ACCESS_GRANTED:
					_settings.close();
					sendNotification(ApplicationFacade.COMMAND_UPDATE_LISTS);
					break;
            }
        }

        protected function get app():Swiftair {
            return viewComponent as Swiftair;
        }
    }
}